//
//  TZTabBarViewController.m
//  wangYiCaiPiao
//
//  Created by mac on 16/1/4.
//  Copyright © 2016年 tz. All rights reserved.
//

#import "TZTabBarViewController.h"
#import "TZHallViewController.h"
#import "TZArenaViewController.h"
#import "TZDiscoverTableViewController.h"
#import "TZCommunicationViewController.h"
#import "TZMeViewController.h"
#import "TZTabBar.h"
#import "TZNavigationController.h"

@interface TZTabBarViewController ()<tabBarDelegate>

@end

@implementation TZTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTabBar];
    // 自定义tabbar
    TZTabBar* tabbar = [[TZTabBar alloc] initWithFrame:self.tabBar.bounds];
    tabbar.backgroundColor = [UIColor blackColor];
    // 设置按钮
    for (int i = 0; i < self.viewControllers.count; i++) {
        // 获取图片
        NSString* imageName = [NSString stringWithFormat:@"TabBar%d", i + 1];
        NSString* imageNameSel = [NSString stringWithFormat:@"TabBar%dSel", i + 1];
        UIImage* image = [UIImage imageNamed:imageName];
        UIImage* imageSel = [UIImage imageNamed:imageNameSel];
        // 通过这个方法 可以创建btn 设置 frame 监听点击
        [tabbar addButtonImage:image andButtonSelectedImage:imageSel];
    }
    [self.tabBar addSubview:tabbar];
    
    tabbar.delegate = self;
}
- (void)setupTabBar {
    //购彩大厅
    UITableViewController *hallController = [[UIStoryboard storyboardWithName:@"TZHallViewController" bundle:nil] instantiateInitialViewController];
    TZNavigationController *hallNav = [[TZNavigationController alloc] initWithRootViewController:hallController];
    //竞技场
    TZArenaViewController *arenaController = [[TZArenaViewController alloc] init];
    TZNavigationController *arenaNav = [[TZNavigationController alloc] initWithRootViewController:arenaController];
    //发现
    TZDiscoverTableViewController *discoverController = [[TZDiscoverTableViewController alloc] init];
    TZNavigationController *discoverNav = [[TZNavigationController alloc] initWithRootViewController:discoverController];
    //开奖信息
    TZCommunicationViewController *communicationController = [[TZCommunicationViewController alloc] init];
    TZNavigationController *communNav = [[TZNavigationController alloc] initWithRootViewController:communicationController];
    //我
    TZMeViewController *meController = [[TZMeViewController alloc] init];
    TZNavigationController *meNav = [[TZNavigationController alloc] initWithRootViewController:meController];
    self.viewControllers = @[hallNav, arenaNav,discoverNav , communNav, meNav];
}
//协议方法
- (void)tabBar:(TZTabBar *)tabBar andWithSelectedIndex:(NSInteger)index {
    self.selectedIndex = index;
}
@end
